<template>
  <div class="mod-tenant__tenant">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item prop="tenantCode" >
        <el-select v-model="dataForm.categoryId" placeholder="档案类型">
          <el-option v-for="category in classList" :key="category.id" :label="category.name" :value="category.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.fileNumber" placeholder="档号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.appraisalPerson" placeholder="鉴定人" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <div class="block">
          <span class="demonstration"></span>
          <el-date-picker
            v-model="appraisalDate"
            @change="dateChange"
            type="datetimerange"
            range-separator="至"
            start-placeholder="鉴定开始日期"
            end-placeholder="鉴定结束日期">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-button @click="getDataList()">{{ $t("query") }}</el-button>
    </el-form>
    <div style="width: 103%; height: 15px; background-color: rgb(240, 242, 245); margin: 0 -21px 15px"></div>
    <el-form-item>
      <el-button type="primary" @click="restore()">还原</el-button>
      <el-button type="primary" @click="authenticated()">鉴定</el-button>
      <el-button type="primary" @click="addOrUpdateHandle()">新增鉴定申请</el-button>
    </el-form-item>
    <el-table ref="multipleTable" stripe v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column label="档号" prop="fileNumber" header-align="center" align="center"></el-table-column>
      <el-table-column label="题名" prop="appraisalTitle" header-align="center" align="center"></el-table-column>
      <el-table-column label="档案类型" prop="categoryName" header-align="center" align="center"></el-table-column>
      <el-table-column label="鉴定类型" prop="type" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.type == 0" size="small" type="success">保管期限鉴定</el-tag>
          <el-tag v-if="scope.row.type == 1" size="small" type="success">密级鉴定</el-tag>
          <el-tag v-if="scope.row.type == 2" size="small" type="success">公开鉴定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="鉴定状态" prop="state" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.state == 0" size="small" type="success">已鉴定</el-tag>
          <el-tag v-if="scope.row.state == 1" size="small" type="danger">待鉴定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="鉴定结果" prop="result" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.result == 0" size="small" type="danger">销毁档案</el-tag>
          <el-tag v-if="scope.row.result == 1" size="small" type="success">还原档案</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="鉴定日期" prop="appraisalDate" header-align="center" align="center"></el-table-column>
      <el-table-column label="创建日期" prop="createDate" header-align="center" align="center"></el-table-column>
      <el-table-column label="创建人" prop="creator" header-align="center" align="center"></el-table-column>
      <el-table-column label="鉴定人" prop="appraisalPerson" header-align="center" align="center"></el-table-column>
    </el-table>
    <el-pagination style="padding: 0px 38%" :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <AppraisalAdd  v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></AppraisalAdd>
    <AppraisalAuthenticated  v-if="isAuthenticatedVisible"  ref="authenticated" @refreshDataList="getDataList" :idList="idList"></AppraisalAuthenticated>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import baseService from "@/service/baseService";
import { IObject } from "@/types/interface";
import { defineComponent, reactive, toRefs } from "vue";
import  AppraisalAdd from "./appraisal-add.vue"
import AppraisalAuthenticated from './appraisal-authenticated.vue'
export default defineComponent({
  components:{
    AppraisalAdd,AppraisalAuthenticated
  },
  setup() {
    const state = reactive({
      getDataListURL: "/archive/appraisal/page",
      getDataListIsPage: true,
      appraisalDate:"",
      idList:[] as IObject[],
      classList: [] as IObject[],
      isAuthenticatedVisible:false,
      dataForm: {
        fileNumber: "",
        appraisalTitle: "",
        categoryId:"",
        appraisalPerson:"",
        appraisalDateBegin:"",
        appraisalDateEnd:""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  created(){
    this.getClassList()
  },
  methods: {
    dateChange(v){
      this.dataForm.appraisalDateBegin = v[0]
      this.dataForm.appraisalDateEnd = v[1]
    },
    restore(){
      console.log(this.dataListSelections)
      baseService.put(`/archive/appraisal/restore`,this.dataListSelections.map(item=>item.id)).then((res) => {
        console.log(res)
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.getDataList();
      });
    },
    getClassList() {
      return baseService.get("/archive/class/list/no-tree").then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.classList = res.data;
      });
    },
    authenticated(){
      this.isAuthenticatedVisible = true;
      this.$nextTick(() => {
        this.idList = this.dataListSelections.map(item=>item.id)
        this.$refs.authenticated.visible=true;
        console.log(this.$refs.authenticated)
      });
    }
  }
});
</script>
